package iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.fragment.producerFragment;


import static android.content.Context.MODE_PRIVATE;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.R;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.activity.ActivityLogin;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.activity.secondActivity.ActivityAppInfo;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.activity.secondActivity.ActivityModifyProfile;


public class FragmentProfile extends Fragment {

    Button btnEditProfile;  // 编辑个人信息页面按钮
    Button btnAboutInfo;    // 查看应用信息页面按钮
    Button btnLogOut;       // 退出登录按钮
    TextView tvusername;
    TextView tvemail;

    public FragmentProfile() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);

        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("ACCOUNT_REMEMBER", MODE_PRIVATE);
        String username = sharedPreferences.getString("username", "未设置");
        String email = sharedPreferences.getString("email", "未设置");

        Log.d("FragmentProfile", "Username: " + username);
        Log.d("FragmentProfile", "Email: " + email);

        tvusername = view.findViewById(R.id.username);
        tvemail = view.findViewById(R.id.email);
        tvusername.setText(username);
        tvemail.setText(email);

        // 个人信息按钮的监听
        btnEditProfile = view.findViewById(R.id.btn_edit_profile);
        btnEditProfile.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), ActivityModifyProfile.class);
            startActivity(intent);
        });

        // 查看应用信息按钮监听
        btnAboutInfo = view.findViewById(R.id.btn_app_info);
        btnAboutInfo.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), ActivityAppInfo.class);
            startActivity(intent);
        });

        // 退出登录按钮监听
        btnLogOut = view.findViewById(R.id.btn_logout);
        btnLogOut.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), ActivityLogin.class);
            startActivity(intent);
        });


        return view;
    }
}
